package sis.ra.yahoor.result;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

import sis.ra.utility.Utils;


public class yahooAbsfrmResults {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String filepath="C:\\Documents and Settings\\I820753\\Desktop\\dataset\\yahoo result_1006\\";
		HashMap<String, ArrayList<String>> companyproducts=parseYahooResults.getCompanyProducts();
		
		File filepaths=new File (filepath);
		String[] files=filepaths.list();
		int sentencenumber=0;
		for (int i=0;i<files.length;i++)
		{
			System.out.println("\n"+filepath+files[i]);
			Utils.writeToFile("C:\\Documents and Settings\\I820753\\Desktop\\dataset\\result1006.all", "\n"+filepath+files[i], true, true);
			//filepath+"Yahoo  Yahoo  Small Business.txt";
//			String company=files[i].split(" ")[0];
//			String companynameorg="";
//			String productname="";
//			String compname="";
//			String product=files[i].substring(company.length(),files[i].length()-4).trim().replace("  ", " ");
//			Iterator<String> companynames=companyproducts.keySet().iterator();
//			while (companynames.hasNext())
//			{
//				companynameorg=companynames.next();
//				String companyname=Utils.removePunctuation(companynameorg);
//				if (files[i].contains(companyname))
//				{
//					System.out.println(companyname);
//					company=companyname.trim();
//					product=files[i].substring(company.length(),files[i].length()-4).trim().replace("  ", " ");
//					System.out.println(product);
//					ArrayList<String> products=companyproducts.get(companynameorg);
//					for (int j=0;j<products.size();j++)
//					{
//						if (Utils.removePunctuation(products.get(j)).contains(Utils.removePunctuation(product)))
//						{
//								productname=products.get(j);
//								System.out.println(product+" "+productname);
//								compname=companynameorg;
//						break;
//						}
//					}
//				}
//			}
			
//			System.out.println(compname+"//"+productname);
//			Utils.writeToFile("C:\\Documents and Settings\\I820753\\Desktop\\dataset\\result1003.all", company+"//"+product, true, true);
//			
			String filename=filepath+files[i];			
			String content=Utils.readFile(filename);
			String [] lines=content.split("\n");
			for (int j=0;j<lines.length;j++)
			{
				if (lines[j].startsWith("COMPANYPRODUCT: "))
				{
					Utils.writeToFile("C:\\Documents and Settings\\I820753\\Desktop\\dataset\\result1006.all", lines[j], true, true);
					break;
				}
			}
//			System.out.println(content);
			content=Utils.readFile(filename.replace("yahoo result_1006", "yahoo result_1003"));
			ArrayList<yahooresults> results=parseYahooResults.getYahooResult(content);
			for (int j=0;j<results.size();j++)
			{
				String abs=results.get(j).getAbs();
				System.out.println(abs);
				Utils.writeToFile("C:\\Documents and Settings\\I820753\\Desktop\\dataset\\result1006.all", abs, true, true);
				sentencenumber=sentencenumber+1;
			}
			System.out.println(results.size());
		}
		System.out.println(sentencenumber);
	}
}
